package com.sky.myapplication.java.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.sky.myapplication.R;
import com.sky.myapplication.java.service.MainService;

/**
 * Created by Min
 * Time 2021/6/19
 * Desc
 */
public class ServiceActivity extends AppCompatActivity implements View.OnClickListener{
    private Button btn_start,btn_stop,btn_bind,btn_unbind, btn_finish;
    private EditText et_search_name;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_service);

//        btn_start = findViewById(R.id.btn_start);
//        btn_stop = findViewById(R.id.btn_stop);
//        btn_bind = findViewById(R.id.btn_bind);
//        btn_unbind = findViewById(R.id.btn_unbind);
//        btn_finish = findViewById(R.id.btn_finish);
//        et_search_name = findViewById(R.id.et_search_name);
//
//        btn_start.setOnClickListener(this);
//        btn_stop.setOnClickListener(this);
//        btn_bind.setOnClickListener(this);
//        btn_unbind.setOnClickListener(this);
//        btn_finish.setOnClickListener(this);
//
//        et_search_name.setOnEditorActionListener(new TextView.OnEditorActionListener() {
//            @Override
//            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
//                if (actionId == EditorInfo.IME_ACTION_SEARCH || (event != null && KeyEvent.KEYCODE_ENTER == event.getKeyCode())) {
////                    keyWord = et_search_name.text.toString()
//                    return true;
//                }
//                return false;
//            }
//        });

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn_start:
                Intent startIntent = new Intent(this, MainService.class);
                startService(startIntent);
                break;
            case R.id.btn_stop:
                Intent stopIntent = new Intent(this, MainService.class);
                stopService(stopIntent);
                break;
            case R.id.btn_bind:

                break;
            case R.id.btn_unbind:

                break;
            case R.id.btn_finish:
//                Handler().postDelayed(Runnable {
//                finish()
//            }, 20000);
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        Intent intent = new Intent();
                        intent.putExtra("a", 1);
                        setResult(1, intent);
                        finish();
                    }
                }, 2000);
                break;
            default:

                break;
        }
    }
}
